﻿namespace OboutInc.ImageZoom
{
    using Obout.Interface;
    using System;
    using System.Web;
    using System.Web.UI;
    using System.Web.UI.WebControls;

    public class DefaultPagerLayout : ITemplate
    {
        private readonly LinkButton _first;
        private readonly OboutDropDownList _imageSizeSelector;
        private readonly Label _imageSizeSelectorLabel;
        private readonly Panel _imageSizeSelectorPanel;
        private readonly LinkButton _last;
        private readonly LinkButton _next;
        private readonly Panel _pageCBC;
        private readonly Panel _pageCBCC;
        private readonly Panel _pageContainer;
        private readonly Panel _pageData;
        private readonly Panel _pager;
        private readonly OboutDropDownList _pageSizeSelector;
        private readonly Label _pageSizeSelectorLabel;
        private readonly Panel _pageSizeSelectorPanel;
        private readonly LinkButton _previous;
        internal OboutInc.ImageZoom.ImageZoom ImageZoom;

        public DefaultPagerLayout(OboutInc.ImageZoom.ImageZoom imageZoom)
        {
            Panel panel6 = new Panel {
                ID = "pageCBCP"
            };
            this._pageCBC = panel6;
            Panel panel7 = new Panel {
                ID = "pageCBCC",
                CssClass = "ob_IZPCc"
            };
            this._pageCBCC = panel7;
            this.ImageZoom = imageZoom;
            if (imageZoom.AllowImageSizeSelection)
            {
                Panel panel = new Panel {
                    ID = "iz_ImageSizeSelectorPanel",
                    CssClass = "ob_izImgsS"
                };
                this._imageSizeSelectorPanel = panel;
                Label label = new Label {
                    Text = "Size:"
                };
                this._imageSizeSelectorLabel = label;
                OboutDropDownList list = new OboutDropDownList {
                    ID = string.Format("{0}_ImageSizeSelector", imageZoom.ID),
                    AutoPostBack = true,
                    Width = Unit.Pixel(100),
                    MenuWidth = Unit.Pixel(150)
                };
                this._imageSizeSelector = list;
            }
            if (imageZoom.AllowPaging)
            {
                if (imageZoom.AllowPageSizeSelection)
                {
                    HttpBrowserCapabilities browser = imageZoom.Page.Request.Browser;
                    Panel panel2 = new Panel {
                        ID = "iz_PageSizeSelectorPanel",
                        CssClass = "ob_izPsS"
                    };
                    this._pageSizeSelectorPanel = panel2;
                    Label label2 = new Label {
                        Text = "Images per page:"
                    };
                    this._pageSizeSelectorLabel = label2;
                    if ((browser.Type == "IE7") || (browser.Type == "IE6"))
                    {
                        this._pageSizeSelectorPanel.Style["display"] = "inline";
                        this._pageSizeSelectorPanel.Style["float"] = "none";
                        this._pageSizeSelectorPanel.Style[HtmlTextWriterStyle.VerticalAlign] = "text-top";
                        this._pageSizeSelectorPanel.Style[HtmlTextWriterStyle.Position] = "absolute";
                        this._pageSizeSelectorLabel.Style["float"] = "none";
                        this._pageSizeSelectorLabel.Style["display"] = "inline";
                    }
                    OboutDropDownList list2 = new OboutDropDownList {
                        ID = string.Format("{0}_PageSizeSelector", imageZoom.ID),
                        AutoPostBack = true,
                        Width = Unit.Pixel(50),
                        MenuWidth = Unit.Pixel(70)
                    };
                    this._pageSizeSelector = list2;
                }
                Panel panel3 = new Panel {
                    CssClass = "ob_izPC"
                };
                this._pageContainer = panel3;
                Panel panel4 = new Panel {
                    ID = "PageData",
                    CssClass = "pageData"
                };
                this._pageData = panel4;
                LinkButton button = new LinkButton {
                    ID = "Next",
                    Text = "",
                    CssClass = "next"
                };
                this._next = button;
                LinkButton button2 = new LinkButton {
                    ID = "First",
                    Text = "",
                    CssClass = "first"
                };
                this._first = button2;
                LinkButton button3 = new LinkButton {
                    ID = "Last",
                    Text = "",
                    CssClass = "last"
                };
                this._last = button3;
                LinkButton button4 = new LinkButton {
                    ID = "Previous",
                    Text = "",
                    CssClass = "prev"
                };
                this._previous = button4;
                Panel panel5 = new Panel {
                    ID = "Pager",
                    CssClass = "pager"
                };
                this._pager = panel5;
                this._next.Attributes.Add("title", "Next");
                this._first.Attributes.Add("title", "First");
                this._last.Attributes.Add("title", "Last");
                this._previous.Attributes.Add("title", "Previous");
            }
        }

        public void InstantiateIn(Control control)
        {
            control.Controls.Clear();
            Panel child = new Panel();
            child.Attributes.Add("class", IzCssSettings.CssGalleryFooterItemContainer);
            if (this.ImageZoom.AllowImageSizeSelection)
            {
                this._imageSizeSelectorPanel.Controls.Add(this._imageSizeSelectorLabel);
                this._imageSizeSelectorPanel.Controls.Add(this._imageSizeSelector);
                child.Controls.Add(this._imageSizeSelectorPanel);
            }
            if (this.ImageZoom.AllowPaging)
            {
                this._pageCBC.Controls.Add(this._last);
                this._pageCBC.Controls.Add(this._next);
                this._pageCBC.Controls.Add(this._pager);
                this._pageCBC.Controls.Add(this._previous);
                this._pageCBC.Controls.Add(this._first);
                this._pageCBC.Controls.Add(this._pageData);
                this._pageCBCC.Controls.Add(this._pageCBC);
                this._pageContainer.Controls.Add(this._pageCBCC);
                if (this.ImageZoom.AllowPageSizeSelection)
                {
                    this._pageSizeSelectorPanel.Controls.Add(this._pageSizeSelectorLabel);
                    this._pageSizeSelectorPanel.Controls.Add(this._pageSizeSelector);
                    this._pageContainer.Controls.Add(this._pageSizeSelectorPanel);
                }
                child.Controls.Add(this._pageContainer);
            }
            control.Controls.Add(child);
        }
    }
}

